package com.odm.communitymanage.ui.DoorSafe

import android.os.Bundle
import androidx.lifecycle.Observer
import com.blankj.utilcode.util.SPUtils
import com.jeremyliao.liveeventbus.LiveEventBus
import com.odm.communitymanage.R
import com.odm.communitymanage.base.BaseMVVMFragment
import com.odm.communitymanage.core.Constants
import kotlinx.android.synthetic.main.fragment_card_detail.*

/**
 * @description: 门禁卡详情页面
 * @author: ODM
 * @date: 2020/4/12
 */

class CardDetailFragment : BaseMVVMFragment(){



    override fun onActivityCreated(savedInstanceState: Bundle?) {
        registerLiveEvent()
        super.onActivityCreated(savedInstanceState)
    }

    override fun initViewModelObserve() {

    }

    override fun initViews() {
        tvAddress_detail.text = SPUtils.getInstance(Constants.SP_USER).getString(Constants.USER_COMMUNITY_NAME)
        tvTenantsName_detail.text = SPUtils.getInstance(Constants.SP_USER).getString(Constants.USER_NAME)
    }

    override fun getLayoutId(): Int {
        return R.layout.fragment_card_detail
    }

    private fun registerLiveEvent(){
        LiveEventBus.get("fake_card_detail" , String::class.java)
            .observeSticky(this  , object : Observer<String> {
                override fun onChanged(t: String?) {
                    tvCardName_detail.text = t
                    ivCardCode_detail.setImageResource(R.mipmap.fake_visitor_code)
                }
            })
    }
}